import { computed, ref } from "vue";

export default function InitHook() {
  const tableData = ref<Array<Base.GeneraDataType>>([]);
  const loading = ref<boolean>(false);
  const weightTotal = computed<number>(() => {
    const allWeight = tableData.value.map((t: any) => t.pickingBoxWeight || 0);
    return allWeight.reduce((a: number, b: number) => (a * 100 + b * 100) / 100, 0).toFixed(2);
  });
  const volumeTotal = computed<number>(() => {
    const allVolume = tableData.value.map((t: any) => t.volumeWeight || 0);
    return allVolume.reduce((a: number, b: number) => (a * 100 + b * 100) / 100, 0).toFixed(2);
  });
  return {
    tableData,
    loading,
    weightTotal,
    volumeTotal
  };
}
